package com.sunny.project;

import java.util.Map;

/**
 * 发型工厂
 * Created by joe on 16-8-1.
 */
public class HairFactory {
	/**
	 * 根据类型来创建对象
	 * @param key
	 * @return
	 */
	public HairInterface getHair(String key){
		if("left".equals(key)){
			return new LeftHair();
		} else if("right".equals(key)){
			return new RightHair();
		}
		return null;
	}

	/**
	 * 根据类的名称(包名+类名)来生产对象
	 * @param className
	 * @return
	 */
	public HairInterface getHaiByClass(String className){
		HairInterface hair = null;
		try {
			hair = (HairInterface) Class.forName(className).newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return hair;
	}

	/**
	 * 根据类名来生产对象
	 * @param key
	 * @return
	 */
	public HairInterface getHaiByClassKey(String key){
		HairInterface hair = null;
		try {
			Map<String,String> map = new PropertiesReader().getProperties();
			hair = (HairInterface) Class.forName(map.get(key)).newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return hair;
	}
}
